//
//  ShippingAddressAddViewController.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/18.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "ShippingAddressAddViewController.h"
#import "BuyOrderContentDetailViewController.h"
#import "LocationListViewController.h"
#import <TZCityList.h>
#import "LJContactManager.h"

@interface ShippingAddressAddViewController ()

@property (strong, nonatomic) UIView *deliverView;
@property (strong, nonatomic) UILabel *deliverL;
@property (strong, nonatomic) UITextField *deliverTextField;
@property (strong, nonatomic) UIImageView *contactIV;
@property (strong, nonatomic) UIView *line1;

@property (strong, nonatomic) UIView *phoneView;
@property (strong, nonatomic) UILabel *phoneL;
@property (strong, nonatomic) UITextField *phoneNumTextField;
@property (strong, nonatomic) UIView *line2;

@property (strong, nonatomic) UIView *addressView;
@property (strong, nonatomic) UILabel *addressL;
@property (strong, nonatomic) UILabel *addressTextL;
@property (strong, nonatomic) UIView *line3;

@property (strong, nonatomic) UIView *addressDetailView;
@property (strong, nonatomic) UILabel *addressDetailL;
@property (strong, nonatomic) UITextField *addressDetailTextField;
@property (strong, nonatomic) UIImageView *line4IV;

@property (strong, nonatomic) UIView *morenAddressView;
@property (strong, nonatomic) UILabel *morenAddressL;
@property (strong, nonatomic) UIButton *morenBtn;

@property (strong, nonatomic) UIImageView *saveIV;
@property (strong, nonatomic) UILabel *saveL;


// 修改的是第几个地址
@property (copy, nonatomic) NSString *index;

@end

@implementation ShippingAddressAddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = WhiteColor;
    
    [self createUI];
    
}

- (void)setShippingModel:(ShippingAdressModel *)shippingModel {
    
    _shippingModel = shippingModel;

    self.deliverTextField.text = shippingModel.name;
    self.phoneNumTextField.text = shippingModel.phone;
    self.addressTextL.text = shippingModel.address;
    self.addressDetailTextField.text = shippingModel.address_detail;
    self.morenBtn.selected = [shippingModel.isdefault boolValue] ? YES : NO;
    
}

#pragma mark -点击通讯录图片
- (void)contactSelectedClick:(UIGestureRecognizer *)recognizer {
    
    NSLog(@"获取通讯录");
    
    [[LJContactManager sharedInstance] selectContactAtController:self complection:^(NSString *name, NSString *phone) {

        self.deliverTextField.text = name;
        self.phoneNumTextField.text = phone;
        
    }];
    
}

#pragma mark -保存按钮点击事件
- (void)saveGestureClick:(UIGestureRecognizer *)recognizer {
    
    if ([self.title isEqualToString:@"修改地址"]) {
        
        NSLog(@"保存修改地址");
        
        [self saveChangeAddress];
        
    }else {
        
        NSLog(@"保存新添加地址");
        
        [self saveNewAddress];
     
    }

}

#pragma mark -保存修改地址
- (void)saveChangeAddress {
    
    NSString *par = [NSString stringWithFormat:@"{\"user_id\" : \"%@\", \"classid\" : \"%@\", \"addressid\" : \"%@\", \"name\" : \"%@\", \"address\" : \"%@\", \"isdefault\" : \"%@\", \"phone\" : \"%@\", \"address_detail\" : \"%@\"}", [RSA encryptString:[CommonUserInfo sharedInstance].user_id publicKey:PublicKey], [RSA encryptString:@"3" publicKey:PublicKey], [RSA encryptString:self.shippingModel.id publicKey:PublicKey], [RSA encryptString:self.deliverTextField.text publicKey:PublicKey], [RSA encryptString:self.addressTextL.text publicKey:PublicKey], [RSA encryptString:[NSString stringWithFormat:@"%d", self.morenBtn.isSelected] publicKey:PublicKey], [RSA encryptString:self.phoneNumTextField.text publicKey:PublicKey], [RSA encryptString:self.addressDetailTextField.text publicKey:PublicKey]];
    
    [PPNetworkHelper POST:@"user/Address/changeAddress" parameters:@{@"json" : par} success:^(id responseObject) {
        
        NSLog(@"保存修改地址:%@",responseObject);
        
        if ([responseObject[@"code"] integerValue] == 1) {
            
//            [[KYAlertView sharedInstance] showAlertViewWithMessage:@"修改地址成功"];
             [[KYAlertView sharedInstance] showAlertViewWithMessage:responseObject[@"msg"]];
            [self.navigationController popViewControllerAnimated:YES];
            
        }else {
            
            [[KYAlertView sharedInstance] showAlertViewWithMessage:responseObject[@"msg"]];
        }
        
    } failure:^(NSError *error) {
        
        if (error) {
            
            [[KYAlertView sharedInstance] showAlertViewWithMessage:Tip];
        }
        
    }];
    
}

#pragma mark -添加新地址接口
- (void)saveNewAddress {
    
    if (self.deliverTextField.text.length <= 0) {
        
        [[KYAlertView sharedInstance] showAlertViewWithMessage:@"请输入收货人姓名"];
        return ;
    }
    
    if (self.phoneNumTextField.text.length <= 0) {
        
        [[KYAlertView sharedInstance] showAlertViewWithMessage:@"请输入收货人手机号"];
        
        return ;
    }
    
    if (self.addressTextL.text.length <= 0) {
        
        [[KYAlertView sharedInstance] showAlertViewWithMessage:@"请选择所在地区"];
        return ;
    }
    
    if (self.addressDetailTextField.text.length <= 0) {
        
        [[KYAlertView sharedInstance] showAlertViewWithMessage:@"请输入详细地址"];
        
        return ;
        
    }

    NSString *isDefault = [NSString stringWithFormat:@"%d", self.morenBtn.isSelected];
    
    NSString *par = [NSString stringWithFormat:@"{\"user_id\" : \"%@\", \"classid\" : \"%@\", \"name\" : \"%@\", \"address\" : \"%@\", \"address_detail\" : \"%@\",\"phone\" : \"%@\", \"isdefault\" : \"%@\", }", [RSA encryptString:[CommonUserInfo sharedInstance].user_id publicKey:PublicKey], [RSA encryptString:@"1" publicKey:PublicKey], [RSA encryptString:self.deliverTextField.text publicKey:PublicKey], [RSA encryptString:self.addressTextL.text publicKey:PublicKey], [RSA encryptString:self.addressDetailTextField.text publicKey:PublicKey], [RSA encryptString:self.phoneNumTextField.text publicKey:PublicKey], [RSA encryptString:isDefault publicKey:PublicKey]];
    
    [PPNetworkHelper POST:@"user/Address/changeAddress" parameters:@{@"json" : par} success:^(id responseObject) {
     
        
        NSLog(@"添加收货地址:%@", responseObject);
        
        if ([responseObject[@"code"] integerValue] == 1) {
            
            [[KYAlertView sharedInstance] showAlertViewWithMessage:@"添加成功"];
           
            
            [self.goodsInfoDict setValue:responseObject[@"data"] forKey:@"addressid"];

            BuyOrderContentDetailViewController *vc = [[BuyOrderContentDetailViewController alloc] init];
            vc.tradeType = 0;
            vc.type = self.classtype;
            vc.dict = self.goodsInfoDict;
            
            
            
            if (self.type == 1) {

                [self.navigationController pushViewController:vc animated:YES];
                
                
            }else {  //返回前一页面
                
                [self.navigationController popViewControllerAnimated:YES];
            }
            
            
            
            
        }else {
            
            [[KYAlertView sharedInstance] showAlertViewWithMessage:responseObject[@"msg"]];
        }
        
    } failure:^(NSError *error) {
        
        if (error) {
            
            [[KYAlertView sharedInstance] showAlertViewWithMessage:Tip];
        }
        
    }];
    
}

#pragma mark -所在地区按钮点击事件
- (void)addressGestureClick:(UIGestureRecognizer *)recognizer {
    
    __weak typeof(self) weakSelf = self;
    TZCityListSelectedStyle *style = [[TZCityListSelectedStyle alloc] init];
    style.selectedColor = [UIColor colorWithRed:96/255.0 green:136/255.0 blue:246/255.0 alpha:1];
    TZCityListMainView *cityView = [[TZCityListMainView alloc] initWithSelectedStyle:nil];
    [cityView show];
    cityView.finishBlock = ^(NSArray *cityArr) {
        weakSelf.addressTextL.text = [cityArr componentsJoinedByString:@""];
    };
}

#pragma mark -设置默认地址按钮点击事件
- (void)morenBtnClick:(UIButton *)btn {
    
    NSLog(@"设置默认地址按钮点击事件");
    
    btn.selected = !btn.selected;
    
}

- (void)createUI {
    
    [self.view addSubview:self.deliverView];
    [self.deliverView addSubview:self.deliverL];
    [self.deliverView addSubview:self.deliverTextField];
    [self.deliverView addSubview:self.contactIV];
    [self.deliverView addSubview:self.line1];
    
    [self.view addSubview:self.phoneView];
    [self.phoneView addSubview:self.phoneL];
    [self.phoneView addSubview:self.phoneNumTextField];
    [self.phoneView addSubview:self.line2];
    
    [self.view addSubview:self.addressView];
    [self.addressView addSubview:self.addressL];
    [self.addressView addSubview:self.addressTextL];
    [self.addressView addSubview:self.line3];
    
    [self.view addSubview:self.addressDetailView];
    [self.addressDetailView addSubview:self.addressDetailL];
    [self.addressDetailView addSubview:self.addressDetailTextField];
    [self.addressDetailView addSubview:self.line4IV];
    
    [self.view addSubview:self.morenAddressView];
    [self.morenAddressView addSubview:self.morenAddressL];
    [self.morenAddressView addSubview:self.morenBtn];
    
    [self.view addSubview:self.saveIV];
    [self.view addSubview:self.saveL];
    
    
    __weak typeof(self) weakSelf = self;
    [self.deliverView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.view.mas_left);
        make.right.mas_equalTo(weakSelf.view.mas_right);
        make.top.mas_equalTo(weakSelf.view.mas_top).with.offset(jisuan(20));;
        make.height.mas_equalTo(jisuan(92));
    
    }];
    [self.deliverL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.deliverView.mas_left).with.offset(jisuan(40));
        make.centerY.mas_equalTo(weakSelf.deliverView.mas_centerY);
        make.width.mas_equalTo(jisuan(80));
        make.height.mas_equalTo(jisuan(34));
    }];
    [self.contactIV mas_makeConstraints:^(MASConstraintMaker *make) {

        make.right.mas_equalTo(weakSelf.deliverView.mas_right).with.offset(-jisuan(60));
        make.centerY.mas_equalTo(weakSelf.deliverView.mas_centerY);
        make.width.mas_equalTo(jisuan(40));
        make.height.mas_equalTo(jisuan(40));

    }];
    [self.deliverTextField mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.deliverL.mas_right).with.offset(jisuan(50));
        make.right.mas_equalTo(weakSelf.contactIV.mas_left).with.offset(-jisuan(40));
        make.centerY.mas_equalTo(weakSelf.deliverL.mas_centerY);
        make.height.mas_equalTo(jisuan(34));

    }];
    [self.line1 mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.deliverView.mas_left).with.offset(jisuan(40));
        make.right.mas_equalTo(weakSelf.deliverView.mas_right).with.offset(-jisuan(40));
        make.bottom.mas_equalTo(weakSelf.deliverView.mas_bottom);
        make.height.mas_equalTo(jisuan(2));
    }];
    [self.phoneView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.view.mas_left);
        make.right.mas_equalTo(weakSelf.view.mas_right);
        make.top.mas_equalTo(weakSelf.deliverView.mas_bottom);
        make.height.mas_equalTo(jisuan(92));

    }];
    [self.phoneL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.phoneView.mas_left).with.offset(jisuan(40));
        make.centerY.mas_equalTo(weakSelf.phoneView.mas_centerY);
        make.width.mas_equalTo(jisuan(100));
        make.height.mas_equalTo(jisuan(34));
    }];

    [self.phoneNumTextField mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.deliverTextField.mas_left);
        make.right.mas_equalTo(weakSelf.phoneView.mas_right).with.offset(-jisuan(40));
        make.centerY.mas_equalTo(weakSelf.phoneView.mas_centerY);
        make.height.mas_equalTo(jisuan(34));

    }];
    [self.line2 mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.phoneView.mas_left).with.offset(jisuan(40));
        make.right.mas_equalTo(weakSelf.phoneView.mas_right).with.offset(-jisuan(40));
        make.bottom.mas_equalTo(weakSelf.phoneView.mas_bottom);
        make.height.mas_equalTo(jisuan(2));
    }];
    [self.addressView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.view.mas_left);
        make.right.mas_equalTo(weakSelf.view.mas_right);
        make.top.mas_equalTo(weakSelf.phoneView.mas_bottom);
        make.height.mas_equalTo(jisuan(92));

    }];
    [self.addressL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.addressView.mas_left).with.offset(jisuan(40));
        make.centerY.mas_equalTo(weakSelf.addressView.mas_centerY);
//        make.width.mas_equalTo(jisuan(100));
//        make.height.mas_equalTo(jisuan(34));
    }];
    [self.addressTextL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.deliverTextField.mas_left);
        make.right.mas_equalTo(weakSelf.addressView.mas_right).with.offset(-jisuan(40));
        make.centerY.mas_equalTo(weakSelf.addressL.mas_centerY);
        make.height.mas_equalTo(jisuan(34));
        
    }];

    [self.line3 mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.addressView.mas_left).with.offset(jisuan(40));
        make.right.mas_equalTo(weakSelf.addressView.mas_right).with.offset(-jisuan(40));
        make.bottom.mas_equalTo(weakSelf.addressView.mas_bottom);
        make.height.mas_equalTo(jisuan(2));
    }];
    [self.addressDetailView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.view.mas_left);
        make.right.mas_equalTo(weakSelf.view.mas_right);
        make.top.mas_equalTo(weakSelf.addressView.mas_bottom);
        make.height.mas_equalTo(jisuan(126));

    }];
    [self.addressDetailL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.addressDetailView.mas_left).with.offset(jisuan(40));
        make.top.mas_equalTo(weakSelf.addressDetailView.mas_top).with.offset(jisuan(28));
//        make.centerY.mas_equalTo(weakSelf.addressDetailView.mas_centerY);
        make.width.mas_equalTo(jisuan(126));
        make.height.mas_equalTo(jisuan(34));
    }];

    [self.addressDetailTextField mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.deliverTextField.mas_left);
        make.right.mas_equalTo(weakSelf.addressDetailView.mas_right).with.offset(-jisuan(40));
        make.centerY.mas_equalTo(weakSelf.addressDetailL.mas_centerY);
        make.height.mas_equalTo(jisuan(34));

    }];
    [self.line4IV mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerX.mas_equalTo(weakSelf.addressDetailView.mas_centerX);
        make.bottom.mas_equalTo(weakSelf.addressDetailView.mas_bottom);
        make.width.mas_equalTo(jisuan(714));
        make.height.mas_equalTo(jisuan(4));
    }];

    [self.morenAddressView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.view.mas_left);
        make.right.mas_equalTo(weakSelf.view.mas_right);
        make.top.mas_equalTo(weakSelf.addressDetailView.mas_bottom);
        make.height.mas_equalTo(jisuan(92));

    }];
    [self.morenAddressL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.mas_equalTo(weakSelf.morenAddressView.mas_centerY);
        make.left.mas_equalTo(weakSelf.morenAddressView.mas_left).with.offset(jisuan(40));
    }];
    [self.morenBtn mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.mas_equalTo(weakSelf.morenAddressView.mas_centerY);
        make.right.mas_equalTo(weakSelf.morenAddressView.mas_right).with.offset(-jisuan(40));
        make.width.mas_equalTo(jisuan(48));
        make.height.mas_equalTo(jisuan(24));
    }];

    [self.saveIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(weakSelf.view.mas_centerX);
        make.bottom.mas_equalTo(weakSelf.view.mas_bottom).with.offset(-jisuan(66));
        make.width.mas_equalTo(jisuan(410));
        make.height.mas_equalTo(jisuan(106));
        
    }];
    [self.saveL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(weakSelf.saveIV.mas_centerX);
        make.centerY.mas_equalTo(weakSelf.saveIV.mas_centerY).with.offset(-jisuan(6));
        
    }];
    
}

#pragma mark -lazy
- (UIView *)deliverView {
    
    if (!_deliverView) {
        
        _deliverView = [[UIView alloc] init];
        _deliverView.backgroundColor = WhiteColor;
    }

    return _deliverView;
}
- (UILabel *)deliverL {
    
    if (!_deliverL) {
        
        _deliverL = [[UILabel alloc] init];
        _deliverL.text = @"收货人";
        _deliverL.textColor = Color333333;
        _deliverL.font = Font(24);
        _deliverL.textAlignment = NSTextAlignmentLeft;
    }
    
    return _deliverL;
    
}
- (UITextField *)deliverTextField {
    
    if (!_deliverTextField) {
        
        _deliverTextField = [[UITextField alloc] init];
        _deliverTextField.placeholder = @"请输入收货人姓名";
        _deliverTextField.font = Font(24);
        _deliverTextField.textAlignment = NSTextAlignmentLeft;
        _deliverTextField.textColor = Color333333;
        
        _deliverTextField.keyboardType = UIKeyboardTypeDefault;
    }
    
    return _deliverTextField;
    
}

- (UIImageView *)contactIV {
    
    if (!_contactIV) {
        
        _contactIV = [[UIImageView alloc] init];
        _contactIV.contentMode = UIViewContentModeScaleAspectFit;
        _contactIV.image = [UIImage imageNamed:@"contactBG"];
        
        _contactIV.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(contactSelectedClick:)];
        [_contactIV addGestureRecognizer:tapGesture];
        
    }
    
    return _contactIV;
}
- (UIView *)line1 {
    
    if (!_line1) {
        
        _line1 = [[UIView alloc] init];
        _line1.backgroundColor = Colordddddd;
    }
    return _line1;
}

- (UIView *)phoneView {
    
    if (!_phoneView) {
        
        _phoneView = [[UIView alloc] init];
        _phoneView.backgroundColor = WhiteColor;
    }
    
    return _phoneView;
}
- (UILabel *)phoneL {
    
    if (!_phoneL) {
        
        _phoneL = [[UILabel alloc] init];
        _phoneL.text = @"手机号码";
        _phoneL.textColor = Color333333;
        _phoneL.font = Font(24);
        _phoneL.textAlignment = NSTextAlignmentLeft;
    }
    
    return _phoneL;
    
}
- (UITextField *)phoneNumTextField {
    
    if (!_phoneNumTextField) {
        
        _phoneNumTextField = [[UITextField alloc] init];
        _phoneNumTextField.placeholder = @"请输入手机号";
        _phoneNumTextField.font = Font(24);
        _phoneNumTextField.textAlignment = NSTextAlignmentLeft;
        _phoneNumTextField.textColor = Color333333;
        
        _phoneNumTextField.keyboardType = UIKeyboardTypeDefault;
    }
    
    return _phoneNumTextField;
    
}

- (UIView *)line2 {
    
    if (!_line2) {
        
        _line2 = [[UIView alloc] init];
        _line2.backgroundColor = Colordddddd;
   
    }
    
    return _line2;
}

- (UIView *)addressView {
    
    if (!_addressView) {
        
        _addressView = [[UIView alloc] init];
        _addressView.backgroundColor = WhiteColor;
        
        UITapGestureRecognizer *addressGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addressGestureClick:)];
        [_addressView addGestureRecognizer:addressGesture];
    }
    
    return _addressView;
}
- (UILabel *)addressL {
    
    if (!_addressL) {
        
        _addressL = [[UILabel alloc] init];
        _addressL.text = @"所在地区";
        _addressL.textColor = Color333333;
        _addressL.font = Font(24);
        _addressL.textAlignment = NSTextAlignmentLeft;
    }
    
    return _addressL;
    
}
- (UILabel *)addressTextL {
    
    if (!_addressTextL) {
        
        _addressTextL = [[UILabel alloc] init];
//        _addressTextL.text = @"所在地区";
        _addressTextL.textColor = Color333333;
        _addressTextL.font = Font(24);
        _addressTextL.textAlignment = NSTextAlignmentLeft;
    }
    
    return _addressTextL;
    
}

- (UIView *)line3 {
    
    if (!_line3) {
        
        _line3 = [[UIView alloc] init];
        _line3.backgroundColor = Colordddddd;
        
    }
    
    return _line3;
}

- (UIView *)addressDetailView {
    
    if (!_addressDetailView) {
        
        _addressDetailView = [[UIView alloc] init];
        _addressDetailView.backgroundColor = WhiteColor;
    }
    
    return _addressDetailView;
}
- (UILabel *)addressDetailL {
    
    if (!_addressDetailL) {
        
        _addressDetailL = [[UILabel alloc] init];
        _addressDetailL.text = @"详细地址：";
        _addressDetailL.textColor = Color333333;
        _addressDetailL.font = Font(24);
        _addressDetailL.textAlignment = NSTextAlignmentLeft;
    }
    
    return _addressDetailL;
    
}
- (UITextField *)addressDetailTextField {
    
    if (!_addressDetailTextField) {
        
        _addressDetailTextField = [[UITextField alloc] init];
        _addressDetailTextField.placeholder = @"如道路、门牌号、小区、楼栋号、单元室等";
        _addressDetailTextField.font = Font(24);
        _addressDetailTextField.textAlignment = NSTextAlignmentLeft;
        _addressDetailTextField.textColor = Color333333;
        
        _addressDetailTextField.keyboardType = UIKeyboardTypeDefault;
    }
    
    return _addressDetailTextField;
    
}

- (UIImageView *)line4IV {
    
    if (!_line4IV) {
        
        _line4IV = [[UIImageView alloc] init];
        _line4IV.contentMode = UIViewContentModeScaleAspectFit;
        _line4IV.image = [UIImage imageNamed:@"purchaseLineBG"];
        
    }
    
    return _line4IV;
}

- (UIView *)morenAddressView {
    
    if (!_morenAddressView) {
        
        _morenAddressView = [[UIView alloc] init];
        _morenAddressView.backgroundColor = WhiteColor;
    }
    
    return _morenAddressView;
}
- (UILabel *)morenAddressL {
    
    if (!_morenAddressL) {
        
        _morenAddressL = [[UILabel alloc] init];
        _morenAddressL.text = @"设为默认地址";
        _morenAddressL.textColor = Color333333;
        _morenAddressL.font = Font(24);
        _morenAddressL.textAlignment = NSTextAlignmentLeft;
    }
    
    return _morenAddressL;
    
}
- (UIButton *)morenBtn {
    
    if (!_morenBtn) {
        
        _morenBtn = [[UIButton alloc] init];
        [_morenBtn setImage:[UIImage imageNamed:@"morenBtnNotSelected"] forState:UIControlStateNormal];
        [_morenBtn setImage:[UIImage imageNamed:@"morenBtnSelected"] forState:UIControlStateSelected];
        
        [_morenBtn addTarget:self action:@selector(morenBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    
    return _morenBtn;
}

- (UIImageView *)saveIV {
    
    if (!_saveIV) {
        
        _saveIV = [[UIImageView alloc] init];
        _saveIV.contentMode = UIViewContentModeScaleAspectFit;
        _saveIV.image = [UIImage imageNamed:@"saveBtnIVbg"];
        _saveIV.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *saveGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(saveGestureClick:)];
        [_saveIV addGestureRecognizer:saveGesture];
        
    }
    
    return _saveIV;
}

- (UILabel *)saveL {
    
    if (!_saveL) {
        
        _saveL = [[UILabel alloc] init];
        _saveL.text = @"保存";
        _saveL.textColor = WhiteColor;
        _saveL.textAlignment = NSTextAlignmentCenter;
        _saveL.font = Font(32);
        
    }
    
    return _saveL;
}

#pragma mark -设置
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
//    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
    
    [super viewWillDisappear:animated];
    
//    self.navigationController.navigationBar.hidden = NO;
//    self.tabBarController.tabBar.hidden = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
